/*
 * Copyright 2008-2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.fsquare.inventory.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.broadleafcommerce.common.presentation.AdminPresentation;
import org.broadleafcommerce.common.presentation.AdminPresentationClass;
import org.broadleafcommerce.common.presentation.client.SupportedFieldType;
import org.broadleafcommerce.core.catalog.domain.Sku;
import org.broadleafcommerce.core.catalog.domain.SkuImpl;


@Entity
@Table(name = "SKU_INVENTORY")
@AdminPresentationClass(friendlyName = "SkuInventoryImpl")
public class SkuInventoryImpl extends AdminFieldsHandler implements SkuInventory {
	
	@Id
	@GeneratedValue
	protected Long id;

    @Column(name = "INVENTORY_QTY_AVAIL", nullable=false)
    @AdminPresentation(friendlyName = "SkuInventoryImpl_quantity", fieldType=SupportedFieldType.INTEGER, order = 9000, groupOrder = 9000, prominent = true, gridOrder = 9000)
    protected Integer quantityAvailable = 0;
    
    @OneToOne(optional = false, targetEntity = SkuImpl.class)
    @JoinColumn(name = "SKU_ID", referencedColumnName = "SKU_ID")
//    @AdminPresentation(friendlyName = "SkuInventoryImpl_sku", order = 1000, groupOrder = 1000, prominent = true, gridOrder = 1000)
    protected Sku sku;
       
    @OneToOne(optional = false, targetEntity = SkuMovementImpl.class)
    @JoinColumn(name = "MOVEMENT_ID", referencedColumnName = "id")
//    @AdminPresentation(friendlyName = "SkuInventoryImpl_movement", order = 1000, groupOrder = 1000, prominent = true, gridOrder = 1000)
    protected SkuMovement movement;

    
    
    @Override
    public void setQuantityAvailable(Integer quantityAvailable) {
        this.quantityAvailable = quantityAvailable;
    }

    @Override
    public Integer getQuantityAvailable() {
        return this.quantityAvailable;
    }

    @Override
	public Long getId() {
		return id;
	}
    
    @Override
	public void setId(Long id) {
		this.id = id;
	}

    @Override
	public Sku getSku() {
		return sku;
	}

	@Override
	public void setSku(Sku sku) {
		this.sku = sku;
	}

	public SkuMovement getMovement() {
		return movement;
	}

	public void setMovement(SkuMovement movement) {
		this.movement = movement;
	}
	
}
